<?php

/** 
 * @author Kinmeic
 * 
 */
class Cookie {
	// THE only instance of the class
	private static $instance;
	
	/**
	 */
	function __construct() {
		
		// TODO - Insert your code here
	}
	
	/**
	 */
	function __destruct() {
		
		// TODO - Insert your code here
	}
	
	public static function getInstance() {
		if ( !isset(self::$instance))
		{
			self::$instance = new self;
		}
		
		return self::$instance;
	}
	
	/**
	 * @param string $name
	 * @param string $default
	 * @return string
	 */
	function __get($name) {
		if (isset($_SESSION[$name])) {
			return $_COOKIE[$name];
		}
	}
	
	/**
	 * @param string $name
	 * @param mixed $value
	 */
	function __set($name, $value) {
		setcookie($name, $value, time() + 31536000);
	}
	
	/**
	 * @param string $name
	 */
	function __isset($name) {
		return isset($_COOKIE[$name]);
	}
	
	/**
	 * @param string $name
	 */
	function __unset($name) {
		setcookie($name, '', time()-31536000);
	}
	
	/**
	 * @return string
	 */
	function __toString(){
		return session_id();
	}
	
	/**
	 * @param string $name
	 * @param string $value
	 * @param int $expire
	 * @param string $path
	 * @param string $domain
	 */
	function set($name, $value, $expire=31536000, $path=NULL, $domain=NULL) {
		setcookie($name, $value, time() + $expire);
	}
	
	/**
	 */
	function destroy() {
		unset($_COOKIE);
	}
	

}

?>